package com.spzx.test.t7;

import lombok.SneakyThrows;
import org.apache.commons.lang3.RandomUtils;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Phone {

    Lock lock = new ReentrantLock();

    @SneakyThrows
    public void call() {
        lock.lock();
        System.out.println(Thread.currentThread().getName() + "正在打电话");
        TimeUnit.SECONDS.sleep(RandomUtils.nextInt(11, 50));
        System.out.println(Thread.currentThread().getName() + "打完电话");
        lock.unlock();
    }

    @SneakyThrows
    public void sendMsg() {
        lock.lock();
        System.out.println(Thread.currentThread().getName() + "正在发短信");
        TimeUnit.SECONDS.sleep(RandomUtils.nextInt(10, 50));
        System.out.println(Thread.currentThread().getName() + "发完短信");
        lock.unlock();
    }


}
